######################
## Create Partial 
## Dependence Plots
#######################

## Seed RNG 
set.seed(831213)

## Get processed data
load("./FullData.RData")

## Create wrapper that will automate
## selection of values at which partial dependence
## function will be evaluated
pdbart.wrapper <- function(ind,arg.list,train.x,train.y){
  return(do.call(pdbart,c(list(xind=ind
                               ,levs=list(seq(min(train.x[,ind],na.rm=TRUE),max(train.x[,ind],na.rm=TRUE),length.out=11))
                               ,x.train = train.x
                               ,y.train = train.y
                               )                                      
                          ,arg.list)))
}



## Get processed data
load("./FullData.RData")
train.data  <- all.data$fData[,-grep("uid|train|fraud",colnames(all.data$fData))]
y.train  <- all.data$fData[,"fraud.score"]

## Get best parameters from parameter sweep
bestParams <- read.csv("./BSParamSweep.csv"
                       ,nrows=1
)[,1:6]


## Estimate barts
# registerDoMC()
# bartFullPlots <- llply(1:ncol(train.data)
#                        ,.fun=pdbart.wrapper
#                        ,arg.list=list(pl=FALSE
#                                       ,k = bestParams$k
#                                       ,power = bestParams$pow
#                                       ,base = bestParams$base
#                                       ,sigdf = bestParams$sigdf
#                                       ,sigquant = bestParams$sigquant
#                                       ,sigest=0.3
#                                       ,nskip = 50e3
#                                       ,ndpost = 10e3
#                                       ,keepevery=5
#                                       ,keeptrainfits=FALSE
#                                       ,ntree = 100
#                                       ,verbose = FALSE
#                        )
#                        ,train.x=train.data
#                        ,train.y=y.train
#                        ,.parallel=TRUE
#                        ,.paropts=list(.packages="BayesTree")
# )
# save(bartFullPlots
#      ,file="./BartPlotObjects.RData")
load("./BartPlotObjects.RData")